<script>
/**
 * 品牌
 * @author:Mumu
 * @date:
 */
import Mod from './articleWrite'
export default {
	components:{
		Mod
	},
	data(){
		return {
			field:[{
				title: '',
				width:'30px',
				slots: { customRender: 'checked' }
			},{
				title: '#',
				width:'30px',
				customRender: ({index}) => index+1
			}, {
				title: '分类',
				dataIndex: 'name',
			}, {
				title: '内容类型',
				dataIndex: 'stype',
				customRender: ({text}) => ['','仅文案','文案加图片','文案加小视频','文案加音频'][text]
			}, {
				title: '内容',
				dataIndex: 'text',
				width:'450px',
			},  {
				title: '状态',
				dataIndex: 'type',
				customRender: ({text}) => ['','待审核','已审核通过','审核未通过'][text]
			}, {
				title: '发布人',
				dataIndex: 'adduser',
				customRender: ({text,record}) => (record.addustype==1?'手机用户：':'管理员：')+text
			},{
				title: '更新时间',
				dataIndex: 'update_time',
			}, {
				title: '操作',
				align: "center",
				width: "200px",
				dataIndex: 'action',
				fixed: 'right',
				slots: { customRender: 'action' }
			}],//表头
			sellist:[],//选项列表
			list:[],//列表
			pagination: {
				defaultCurrent: 1,
				current: 1,
				defaultPageSize: 10,
				pageSize: 10,
				showQuickJumper: true,
				showSizeChanger: true,
				showTotal: (total, range) => `共${total}条`,
				total: 0,
			},
			listloading:false,
			search:{},
		}
	},
	created(){
		this.getbrand();
	},
	mounted() {
		this.$nextTick(()=>{
			this.getList();
		})
	},
	methods:{
		async getbrand(){
			let rs	=	await this.muajax.fodMinList();
			if(rs.status==200){
				this.sellist=rs.data;
			}
		},//获取分类
		async getList() {
			if(this.listloading) return;
			this.listloading		=	true;
			let rs	=	await this.muajax.fodfodList({
				...this.search,
				page:this.pagination.current,
				size:this.pagination.pageSize,
			});
			this.listloading		=	false;
			// if (rs.status!=200) return;
			if ( this.pagination.current == 1 ){
				this.records		=	[];
			}
			this.list=rs.data;
			this.pagination.total=rs.sum;
		},//列表
		async del(k){
			if(!await this.$showfirm('确定要删除该数据吗？')) return;
			let rs = await this.muajax.fodfodDel({
				ids:[this.list[k].id]
			});
			if(rs.status==200){
				this.$message.success('删除成功');
				if(this.list.length==1){
					this.research();
				}else{
					this.getList();
				}
				
			}
		},//删除
		async settype(v,type){
			let rs	=	await this.muajax.fodsettype({
				id:v.id,
				type
			});
			if(rs.status==200){
				v.type=type;
				this.$message.success(type==2?'审核为通过':'审核为不通过');
			}
		},//获取分类
		research(){
			this.pagination.current=1;
			this.getList();
		},//搜索重置
		applysDataTableChangeHandle(pagination, filters, sorter) {
			this.pagination.current		= pagination.current;
			this.pagination.pageSize	= pagination.pageSize;
			this.getList();
		},//操作分页控制
	},
	computed: {

	},
}
</script>
<template>

	<a-card>
		<a-form layout="inline" class="text-center">
			<a-form-item label="搜索">
				<a-select
					placeholder="请选择分类"
					style="width:180px"
					:dropdownMatchSelectWidth="false"
					v-model:value="search.sid"
					:allowClear="true"
				>
					<a-select-option v-for="v in sellist" :key="v.id">{{ v.name }}</a-select-option>
				</a-select>
			</a-form-item>
			<a-form-item>
				<a-select
					placeholder="请选择内容类型"
					style="width:180px"
					:dropdownMatchSelectWidth="false"
					v-model:value="search.stype"
					:allowClear="true"
				>
					<a-radio :value="1">仅文案</a-radio>
					<a-radio :value="2">文案加图片</a-radio>
					<a-radio :value="3">文案加小视频</a-radio>
					<a-radio :value="4">文案加音频</a-radio>
				</a-select>
			</a-form-item>
			<a-form-item>
				<a-select
					placeholder="请选择查询状态"
					style="width:180px"
					:dropdownMatchSelectWidth="false"
					v-model:value="search.type"
					:allowClear="true"
				>
					<a-radio :value="1">待审核内容</a-radio>
					<a-radio :value="2">已审核内容</a-radio>
					<a-radio :value="3">未通过审核</a-radio>
				</a-select>
			</a-form-item>
			<a-form-item>
				<a-input
					v-model:value="search.mobilephone"
					placeholder="请输入用户账号"
					style="width:250px"
				/>
			</a-form-item>
			<a-form-item>
				<a-input
					v-model:value="search.keyword"
					placeholder="请输入标题或内容"
					style="width:250px"
				/>
			</a-form-item>
			<a-form-item>
				<a-range-picker
                    @change="data=>[search.doctimeStart,search.doctimeEnd]=data"
                    format="YYYY/MM/DD"
                    valueFormat="YYYY/MM/DD"
                    :placeholder="['文案发布时间范围开始','文案发布时间范围结束']"
                />
			</a-form-item>
			<a-form-item>
				<a-space>
					<a-button type="primary" @click="research()">搜索</a-button>
					<!-- <a-button type="default">重置</a-button> -->
				</a-space>
			</a-form-item>
		</a-form>
		<div class="mm-t-20 mm-b-15">
			<a-space>
				<a-button type="primary" @click="$refs.mod.show(true)">+ 新建</a-button>
				<!-- <a-button type="primary" danger>删除</a-button> -->
			</a-space>
		</div>


		<a-table
			:columns="field"
			:data-source="list"
			:pagination="pagination"
			:loading="listloading"
			:scrollToFirstRowOnChange="true"
			@change="page=>applysDataTableChangeHandle(page)"
			size="small"
			:row-key="(record)=>JSON.stringify(record)"
		>
			<template #checked="{record}">
				<!-- <a-checkbox v-model:checked="record.checked"></a-checkbox> -->
			</template>
			<template #action="{record,index}">
				<a-space>
					<template v-if="record.type==1">
						<a-button type="primary" ghost @click="settype(record,2)" title="审核通过">
							<template #icon>
								<CheckCircleOutlined />
							</template>
						</a-button>
						<a-button danger @click="settype(record,3)" title="审核不通过">
							<template #icon>
								<CloseCircleOutlined />
							</template>
						</a-button>
					</template>
					

					<a-button type="primary" @click="$refs.mod.show(true,record)" title="编辑">
						<template #icon>
							<EditOutlined />
						</template>
					</a-button>
					<a-button type="primary" danger @click="del(index)" title="删除">
						<template #icon>
							<DeleteOutlined />
						</template>
					</a-button>
				</a-space>
			</template>
		</a-table>

	</a-card>
	<Mod ref="mod" />
</template>
<style lang="less" scoped>

</style>